/**
 * throw
 * 抛出异常
 */
function* foo(initial) {
  console.log('-----函数开始执行-----')

  const value1 = 1
  console.log(value1)
  try {
    yield value1 * initial
  } catch (err) {
    console.log(err)
    //catch中依然可以使用yield，进行分段操作
    yield 'catch yield'
  }

  const value2 = 2
  console.log(value2)
  yield value2

  const value3 = 3
  console.log(value3)
  yield

  console.log('-----函数结束执行-----')
}

const generator = foo(90)

console.log(generator.next())

//此处的throw是针对的上一个yield，如果生成器中有捕获异常，则会继续执行第二阶段代码，否则终止
console.log(generator.throw('res1 error...'))
console.log(generator.next())
